var gulp = require('gulp');
var gutil = require('gulp-util');
var bower = require('bower');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var minifyCss = require('gulp-minify-css');
var rename = require('gulp-rename');
var sh = require('shelljs');
var sprity = require('sprity');
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');
var strip = require('gulp-strip-comments');
var angularTemplateCache = require('gulp-angular-templatecache')
var ngmin = require('gulp-ngmin');
var runSequence = require('gulp-run-sequence');
var preprocess = require('gulp-preprocess');
var minifyHtml = require('gulp-minify-html');

gulp.task('default',function(){
   // place code for your default task here
});

gulp.task('sprites', function () {
  return sprity.src({
    src: './public/img/about/member/*.{png,jpg}',
    split: true,
    name: 'icons',
    style: './sprite.css',
    prefix: 'img',
    margin: 17
    // ... other optional options 
    // for example if you want to generate scss instead of css 
    // processor: 'sass', // make sure you have installed sprity-sass 
  })
  .pipe(gulpif('*.png', gulp.dest('./public/dist/image/'), gulp.dest('./public/dist/css/')))
});

gulp.task('minifyCss', function(done) {
  gulp.src('./public/css/*.css')
    .pipe(minifyCss({keepBreaks: false}))
    .pipe(concat('all.css'))
    .pipe(rename({
        suffix: '.min'
    }))
    .pipe(gulp.dest('./public/dist/css/'))
    .on('end', done);
});

gulp.task('minifyDevJs', function(done) {
  gulp.src(['./public/js/*.js'])
    .pipe(concat('dev.js'))
    .pipe(ngmin())
    .pipe(uglify({mangle: false}))
    .pipe(rename({
        suffix: '.min'
    }))
    .pipe(gulp.dest('./public/dist/js/'))
    .on('end', done);
});

gulp.task('dev', function() {
  gulp.src('./build/master_tpl.blade.php')
    .pipe(preprocess({context: { NODE_ENV: 'dev', DEBUG: true}}))
    .pipe(concat('master.blade.php'))
    .pipe(gulp.dest('./app/views/layouts/'));
});

gulp.task('prod', function() {
  gulp.src('./build/master_tpl.blade.php')
    .pipe(preprocess({context: { NODE_ENV: 'prod', DEBUG: true}}))
    .pipe(concat('master.blade.php'))
    .pipe(gulp.dest('./app/views/layouts/'));
});
